package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Document;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class DocumentDao {
	private DBHelp<Document> db = new DBHelp<Document>();
	public List<Document> findByProjectId(int projectid){
		String sql = "SELECT id,content,title,createtime,projectid,userid FROM t_document WHERE projectid = ?";
		return db.executeQueryForList(sql, new DocumentRowMapper(), projectid);
	}
	private class DocumentRowMapper implements RowMapper<Document>{

		public Document mapperRow(ResultSet rs) throws SQLException {
			// TODO Auto-generated method stub
			Document d = new Document();
			d.setContent(rs.getString("content"));
			d.setCreateTime(rs.getString("createTime"));
			d.setId(rs.getInt("id"));
			d.setTitle(rs.getString("title"));
			d.setUserID(rs.getInt("userID"));
			d.setProjectID(rs.getInt("projectID"));
			return d;
		}
		
	}
}
